﻿Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        GridView1.AllowPaging = True
        Try
            Dim cmd As New SqlCommand("select username,firstname,emailid,banned from users where username<>'admin'", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()
        Catch
        End Try

    End Sub

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Try
            Dim uname As String = GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text
            Dim status As String = GridView1.Rows(GridView1.SelectedIndex).Cells(2).Text
            cn.Open()
            If status = "allowed" Then
                Dim cmd As New SqlCommand("update users set banned='banned' where username='" + uname + "'", cn)
                cmd.ExecuteNonQuery()
            Else
                Dim cmd As New SqlCommand("update users set banned='allowed' where username='" + uname + "'", cn)
                cmd.ExecuteNonQuery()
            End If
            cn.Close()
            Response.Redirect("delete user.aspx")
        Catch
        End Try

    End Sub
End Class
